# -*- Python -*-
#
# Copyright (C) 2012 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#
### Configuration file for target side debugger integration tests
#
# Parameters available through lit --param options:
#   android_sdk - Path to the android SDK directory 
#   sdk_version - SDK target to pass to 'android' for creating test projects
#   minimum_sdk - SDK minimum version to embed in AndroidManifest.xml

# If the user is running an individual tests directory, we have to load
# the libbcc site configuration first
build_top = getattr(config, 'build_top', None)
if build_top is None:
  lit.load_config(config, os.path.join(os.getenv('ANDROID_BUILD_TOP',
    '../../../../../'), 'frameworks', 'compile', 'libbcc', 'tests',
    'debuginfo', 'lit.site.cfg'))
  build_top = config.build_top

# Default SDK path and version
default_sdk_dir = os.path.join(config.base_build_path, 'sdk', 'android-sdk_' \
                    + os.getenv('TARGET_BUILD_VARIANT') + '.' \
                    + os.getenv('USER') + '_linux-x86')
default_sdk_version = "android-JellyBean"
default_minimum_sdk = "JellyBean"

# Set up the suite name, extensions that are recognized as testcases, and
# the target triple string that must be used in cases marked expected failures
config.name = 'target_renderscript_debug'
config.suffixes = ['.rs']
config.target_triple = 'target-bcc'

# Output directory in the android source tree
if os.getenv('TARGET_BUILD_TYPE', None) == 'debug':
  config.test_exec_root = os.path.join(config.build_top, 'out', 'debug',
    'target', 'tests', 'rsdebug')
else:
  config.test_exec_root = os.path.join(config.build_top, 'out', 'target',
    'tests', 'rsdebug')

#
## Set up SDK path and version
#
config.sdk_dir = lit.params.get('android_sdk', default_sdk_dir)
if not os.path.isdir(config.sdk_dir):
  lit.fatal("Android SDK directory " + config.sdk_dir + " does " \
    + "not exist. Check --param android_sdk=<path> lit parameter in test " \
    + "suite invocation.")

config.sdk_version = lit.params.get('sdk_version', default_sdk_version)
config.minimum_sdk = lit.params.get('minimum_sdk', default_minimum_sdk)

#
## Set up environment variables
#

# Propagate ANDROID_PRODUCT_OUT to child environment
config.environment['ANDROID_PRODUCT_OUT'] = os.getenv('ANDROID_PRODUCT_OUT')
config.environment['ANDROID_BUILD_TOP'] = os.getenv('ANDROID_BUILD_TOP')

config.environment['DEBUGGER'] = config.gdb
config.environment['DEBUGGER_ARGS'] = "-d " + config.gdb_plugin_directory + ' '

if not lit.quiet:
    lit.note('using Android SDK: %r' % config.sdk_dir)
    lit.note('using Android SDK Version: %r' % config.sdk_version)
    lit.note('using test apk builder: %r' % config.build_test_apk)
    lit.note('using GDB plugin directory: %r' % config.gdb_plugin_directory)

# Apply target-side test macro substitutions
config.substitutions.append( ('%build_test_apk_opts', ' --sdk ' + config.sdk_dir \
                                                    + ' --target ' + config.sdk_version \
                                                    + ' --minsdk ' + config.minimum_sdk))
config.substitutions.append( ('%build_test_apk', ' ' + config.sh \
                                               + ' ' + config.build_test_apk + ' '))
